package com.seu.pojo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

public class People {

    //如果显示定义了Autowired的required属性为false，说明这个对象可以为null，否则不允许为空
    @Autowired(required = false)
    private Cat cat;

    @Autowired      //一般直接在属性上使用
    @Qualifier("dog")               //相当于@Resource的byName
    private Dog dog;

    private String name;

    public Cat getCat() {
        return cat;
    }

/*
    //由于Autowired注解通过反射实现，所以去掉set方法依旧可以注入
    public void setCat(Cat cat) {
        this.cat = cat;
    }
*/

    public Dog getDog() {
        return dog;
    }

/*
    //Autowired也可以在set方法上用
    //@Autowired
    public void setDog(Dog dog) {
        this.dog = dog;
    }
*/

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "People{" +
                "cat=" + cat +
                ", dog=" + dog +
                ", name='" + name + '\'' +
                '}';
    }
}
